﻿using System;
using System.Collections.Generic;
using System.Text;
using RollBackLib.src.core;

namespace RollBackLib.src.utils
{
    /// <summary>
    /// Implements utilities for Scheduling of jobs
    /// </summary>
    public class Scheduler
    {
        private Scheduler() 
        {
            
        }
        /// <summary>
        /// How often should the job be run
        /// </summary>
        public static string[] m_howOftenList = { "Daily", "Weekly", "Monthly" };

        public static string[] m_whatTimeOfDayList = {   "12:00 AM", "1:00 AM", "2:00 AM", "3:00 AM", "4:00 AM", "5:00 AM", "6:00 AM", "7:00 AM",
                                                  "8:00 AM", "9:00 AM", "10:00 AM", "11:00 AM", "12:00 PM (Noon)", "1:00 PM", "2:00 PM",
                                                  "3:00 PM", "4:00 PM", "5:00 PM", "6:00 PM", "7:00 PM", "8:00 PM", "9:00 PM", "10:00 PM", "11:00 PM",
                                              };

        /// <summary>
        /// If the m_runHowOftenItems is set to Weekly then the user can choose on what day to run the job.
        /// </summary>
        public static string[] m_whatDayOfWeekList = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

        /// <summary>
        /// Choices on what date to run of "How Often" is set to "Monthly"
        /// </summary>
        public static string[] m_whatDateList = { "1", "2", "3", "4", "5", "6", "7", "8" };


        /// <summary>
        /// Convert an index into m_whatTimeOfDayList into a 24 hour hour value
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public static void toTimeOfDay(int index,ref int hour)
        {
            if (index < 0 || index > m_whatTimeOfDayList.Length)
            {
                throw new BackupException("Time of day index " + index + " is out of bounds.  Valid range is from 0 to " + m_whatTimeOfDayList.Length);
            }
            string[] a1 = m_whatTimeOfDayList[index].Split(' ');
            string[] a2 = a1[0].Split(':');
            hour = Int32.Parse(a2[0]);
            if(string.Compare(a1[1],"PM",true)==0) {
                hour += 12;
            }
            else if (hour == 12)
            {
                hour = 0;
            }
        }
    }
}
